package edu.pitt.dbmi.odie.gapp.gwt.model;

import java.util.Date;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.google.appengine.api.datastore.Key;

import edu.pitt.dbmi.odie.gapp.gwt.client.dao.ODIE_DaoAnalysis;
import edu.upmc.opi.caBIG.common.CaBIG_UUIdGenerator;

@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class ODIE_Analysis {

	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	private Key id;

	@Persistent
	private String odieId;

	@Persistent
	private String userId ;
	
	@Persistent
	private String directoryHandle;

	@Persistent
	private String title;
	
	@Persistent
	private String analysisStatus;

	@Persistent
	private Date creationDate;
		
	@Persistent
	private Date modifiedDate;
	
	@Persistent
	private Integer unitsRequested;
	
	@Persistent
	private Integer unitsCompleted;
	
	@Persistent
	private String processingUnitName;
	
	@Persistent
	private Integer subUnitsRequested;
	
	@Persistent
	private Integer subUnitsCompleted;
	
	@Persistent
	private String processingSubUnitName;
	
	@Persistent
	private boolean isSelected;
	
	@Persistent
	private boolean longestOnly = false ;
	
	@Persistent
	private boolean wholeWordOnly = true ;
	
	@Persistent
	private String stopWords;
	
	@Persistent
	private boolean withDefaultStopWords = false ;
	
	@Persistent
	private int minTermSize = 0 ;
	
	@Persistent
	private boolean scored = true ;
	
	@Persistent
	private String localOntologyIDs;
	
	@Persistent
	private String localSemanticTypeIDs;
	
	@Persistent
	private int levelMin = 0 ;
	
	@Persistent
	private int levelMax = 0 ;
	
	@Persistent
	private boolean activateMappings = false ;
	
	@Persistent
	private String mappingTypes;
		
	public ODIE_Analysis() {
		this.odieId = CaBIG_UUIdGenerator.getUUID() ;
	}

	public String getOdieId() {
		return this.odieId;
	}

	public void setOdieId(String odieId) {
		this.odieId = odieId;
	}

	public String getUserId() {
		return userId;
	}

	public void setUserId(String userId) {
		this.userId = userId ;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}
	
	public String getDirectoryHandle() {
		return directoryHandle;
	}

	public void setDirectoryHandle(String directoryHandle) {
		this.directoryHandle = directoryHandle;
	}

	public Date getCreationDate() {
		return creationDate;
	}

	public void setCreationDate(Date creationDate) {
		this.creationDate = creationDate;
	}
	
	public String getAnalysisStatus() {
		return analysisStatus;
	}

	public void setAnalysisStatus(String analysisStatus) {
		this.analysisStatus = analysisStatus;
	}

	public Date getModifiedDate() {
		return modifiedDate;
	}

	public void setModifiedDate(Date modifiedDate) {
		this.modifiedDate = modifiedDate;
	}

	public Integer getUnitsRequested() {
		return unitsRequested;
	}

	public void setUnitsRequested(Integer unitsRequested) {
		this.unitsRequested = unitsRequested;
	}

	public Integer getUnitsCompleted() {
		return unitsCompleted;
	}

	public void setUnitsCompleted(Integer unitsCompleted) {
		this.unitsCompleted = unitsCompleted;
	}

	public String getProcessingUnitName() {
		return processingUnitName;
	}

	public void setProcessingUnitName(String processingUnitName) {
		this.processingUnitName = processingUnitName;
	}
	
	public Integer getSubUnitsRequested() {
		return subUnitsRequested;
	}

	public void setSubUnitsRequested(Integer subUnitsRequested) {
		this.subUnitsRequested = subUnitsRequested;
	}

	public Integer getSubUnitsCompleted() {
		return subUnitsCompleted;
	}

	public void setSubUnitsCompleted(Integer subUnitsCompleted) {
		this.subUnitsCompleted = subUnitsCompleted;
	}
	
	public String getProcessingSubUnitName() {
		return processingSubUnitName;
	}

	public void setProcessingSubUnitName(String processingSubUnitName) {
		this.processingSubUnitName = processingSubUnitName;
	}
	
	public boolean isSelected() {
		return isSelected;
	}

	public void setSelected(boolean isSelected) {
		this.isSelected = isSelected;
	}
	
	public boolean isLongestOnly() {
		return longestOnly;
	}

	public void setLongestOnly(boolean longestOnly) {
		this.longestOnly = longestOnly;
	}

	public boolean isWholeWordOnly() {
		return wholeWordOnly;
	}

	public void setWholeWordOnly(boolean wholeWordOnly) {
		this.wholeWordOnly = wholeWordOnly;
	}

	public String getStopWords() {
		return stopWords;
	}

	public void setStopWords(String stopWords) {
		this.stopWords = stopWords;
	}

	public boolean isWithDefaultStopWords() {
		return withDefaultStopWords;
	}

	public void setWithDefaultStopWords(boolean withDefaultStopWords) {
		this.withDefaultStopWords = withDefaultStopWords;
	}

	public int getMinTermSize() {
		return minTermSize;
	}

	public void setMinTermSize(int minTermSize) {
		this.minTermSize = minTermSize;
	}

	public boolean isScored() {
		return scored;
	}

	public void setScored(boolean scored) {
		this.scored = scored;
	}

	public String getLocalOntologyIDs() {
		return localOntologyIDs;
	}

	public void setLocalOntologyIDs(String localOntologyIDs) {
		this.localOntologyIDs = localOntologyIDs;
	}

	public String getLocalSemanticTypeIDs() {
		return localSemanticTypeIDs;
	}

	public void setLocalSemanticTypeIDs(String localSemanticTypeIDs) {
		this.localSemanticTypeIDs = localSemanticTypeIDs;
	}

	public int getLevelMin() {
		return levelMin;
	}

	public void setLevelMin(int levelMin) {
		this.levelMin = levelMin;
	}

	public int getLevelMax() {
		return levelMax;
	}

	public void setLevelMax(int levelMax) {
		this.levelMax = levelMax;
	}

	public boolean isActivateMappings() {
		return activateMappings;
	}

	public void setActivateMappings(boolean activateMappings) {
		this.activateMappings = activateMappings;
	}

	public String getMappingTypes() {
		return mappingTypes;
	}

	public void setMappingTypes(String mappingTypes) {
		this.mappingTypes = mappingTypes;
	}
	
	public ODIE_DaoAnalysis convertToClientSideRecord() {
		ODIE_DaoAnalysis result = new ODIE_DaoAnalysis() ;
		result.setOdieId(this.odieId) ;
		result.setUserId(userId) ;
		result.setTitle(title) ;
		result.setDirectoryHandle(directoryHandle) ;
		result.setAnalysisStatus(analysisStatus) ;
		result.setCreationDate(creationDate) ;
		result.setModifiedDate(modifiedDate) ;
		result.setProcessingUnitName(processingUnitName) ;
		result.setUnitsCompleted(unitsCompleted) ;
		result.setUnitsRequested(unitsRequested) ;
		result.setProcessingSubUnitName(processingSubUnitName) ;
		result.setSubUnitsCompleted(subUnitsCompleted) ;
		result.setSubUnitsRequested(subUnitsRequested) ;
		result.setLongestOnly(isLongestOnly()) ;
		result.setWholeWordOnly(isWholeWordOnly()) ;
		result.setStopWords(getStopWords()) ;
		result.setWithDefaultStopWords(isWithDefaultStopWords()) ;
		result.setMinTermSize(getMinTermSize()) ;
		result.setScored(isScored()) ;
		result.setLocalOntologyIDs(getLocalOntologyIDs()) ;
		result.setLocalSemanticTypeIDs(getLocalSemanticTypeIDs()) ;
		result.setLevelMin(getLevelMin()) ;
		result.setLevelMax(getLevelMax()) ;
		result.setActivateMappings(isActivateMappings()) ;
		result.setMappingTypes(getMappingTypes()) ;
		return result ;
	}
	
	public String toXml() {
		StringBuffer sb = new StringBuffer();
		if (id != null) {
	        sb.append("<analysis>") ;
			sb.append("<id>" + getOdieId() + "</id>");
			sb.append("<odieId>" + getOdieId() + "</odieId>");
			sb.append("<userId>" + getUserId() + "</userId>") ;
			sb.append("<title>" + getTitle() + "</title>");
			sb.append("<modifiedDate>" + getModifiedDate() + "</modifiedDate>");
			sb.append("<analysisStatus>" + getAnalysisStatus() + "</analysisStatus>");
			sb.append("<unitsRequested>" + getUnitsRequested() + "</unitsRequested>");
			sb.append("<unitsCompleted>" + getUnitsCompleted() + "</unitsCompleted>");
			sb.append("<progress>" + "" + "</progress>");
			sb.append("<isSelected>" + isSelected() + "</isSelected>") ;
			sb.append("</analysis>") ;
		}
		return sb.toString();
	}

}
